package cn.mywcc.filter;

import cn.mywcc.util.Rs4Filter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;


public class PermissionCheckerFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        String groupId = request.getHeaders().getFirst("groupId");
        URI uri = request.getURI();
        System.out.println(uri);
        ServerHttpResponse response = exchange.getResponse();
        return response.writeWith(Rs4Filter.createData(
                response,
                HttpStatus.NON_AUTHORITATIVE_INFORMATION,
                "没有权限"));

    }

    @Override
    public int getOrder() {
        return 2;
    }
}
